local thbattle__uuz_yousi = fk.CreateSkill {

  name = "thbattle__uuz_yousi",

  tags = { Skill.Compulsory, },

}



thbattle__uuz_yousi:addEffect("active", {
  name = "thbattle__uuz_yousi",
  prompt = "#thbattle__uuz_yousi",
  mute=true,
  target_num = 1,
  target_filter =function (self, player, to_select, selected, selected_cards, card, extra_data)
    return #selected == 0 and player ~= to_select
  end,
  max_phase_use_time = 1,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    if player.phase == Player.Play then
      room:addPlayerMark(player, "thbattle__uuz_yousi")
    end
    player:broadcastSkillInvoke(thbattle__uuz_yousi.name,1)
    room:notifySkillInvoked(player,thbattle__uuz_yousi.name,"offensive")
    THB_Utility.addStatusMark(target, "@@thbattle__uuz_yousi")
    room:loseHp(target, 1, thbattle__uuz_yousi.name)
  end
})

thbattle__uuz_yousi:addEffect(fk.EventPhaseStart, {
  mute=true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(thbattle__uuz_yousi.name) and player.phase == Player.Finish and
        table.find(player.room:getOtherPlayers(player), function(p)
          return p.hp == 1
        end) and player:getMark("thbattle__uuz_yousi") == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(thbattle__uuz_yousi.name,2)
    room:notifySkillInvoked(player,thbattle__uuz_yousi.name,"offensive")
    for _, p in pairs(table.filter(player.room:getOtherPlayers(player), function(p)
      return p.hp == 1
    end)) do
      room:loseHp(p, 1, thbattle__uuz_yousi.name)
    end
  end,
})
thbattle__uuz_yousi:addEffect(fk.EventPhaseEnd, {
  can_refresh = function(self, event, target, player, data)
    return target==player and player:hasSkill(thbattle__uuz_yousi.name) and player.phase==Player.Finish 
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      if p:getMark("@@thbattle__uuz_yousi") > 0 then
        room:recover({
          who =p,
          num = p:getMark("@@thbattle__uuz_yousi"),
          skillName = thbattle__uuz_yousi.name,
          recoverBy = player,
        })
        THB_Utility.removeStatusMark(p, "@@thbattle__uuz_yousi",p:getMark("@@thbattle__uuz_yousi"))
      end
      if p:getMark("thbattle__uuz_yousi") > 0 then
        room:removePlayerMark(p, "thbattle__uuz_yousi")
      end
    end
  end
})

return thbattle__uuz_yousi